home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1158 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.1 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Better template syntax?
  5. Date: 18 Apr 1996 16:54:19 GMT
  6. Organization: Datalytics, Inc
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <317673A9.2EBB@datalytics.com>
  9. References: <31741E6C.53CA@cs.tu-berlin.de>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset="us-ascii"
  13. Content-Transfer-Encoding: 7bit
  14. X-Nntp-Posting-Host: 204.62.224.71
  15. X-Mailer: Mozilla 2.0 (WinNT; I)
  16. X-Lines: 51
  17. Content-Length: 2155
  18. Originator: clamage@taumet
  19.  
  20. Roman Lechtchinsky wrote:
  21. > Hi,
  22. > sorry for being curious but I'm only human... My question is: when declaring
  23. > templates, why isn't it required to declare what one expects of the
  24. > template's parameters? Let's create a template function:
  25. > template<class T> bool equal( const T& t1, const T& t2 )
  26. > {
  27. >   return t1==t2;
  28. > }
  29. > Now, personally I would prefer to write something like:
  30. > template<class T { bool operator==( const T& t ) const; }> ...
  31. > This would make both the development and the use of templates much easier (
  32. > to me, at least ). No need for writing lots of comments explaining what
  33. > interface T should provide; no need for reading the source code of "equal" if
  34. > it is part of a third-party library with poor interface documentation; no
  35. > need to worry about implicit conversions - sounds like a lot of advantages.
  36. > Then again, I imagine that this approach would make templates more efficient
  37. > and easier to implement.
  38. > Now, what I'd like to know is if something like this has been considered and
  39. > rejected ( and why ) and what other people think about it ( would this be
  40. > really easier to use in practice; do you consider it more elegant than the
  41. > current approach ). Thanks in advance.
  42.  
  43. I can't answer whether this has been considered (or rejected), 
  44. but I can see a problem with your proposal.  What if a template 
  45. required ten, fifteen, twenty mfs in its parameterizing type?  
  46. What if those mfs have many parameters?  The resulting list of 
  47. mfs and parameters would become quite ungainly.
  48.  
  49. Perhaps you could declare a class with the exact interface you 
  50. expect and provide that as a model for the parameterizing type?  
  51. This still leaves issues like equivalence.  Are implicit 
  52. conversion allowed in mfs of a parameterizing type in order to 
  53. match the model?  At what point do you decide there is no match?
  54.  
  55. What about the template code?  What if it you misuse the 
  56. parameterizing type relative to your model?  Is the model wrong 
  57. or is your code wrong?
  58.  
  59. There's probably a lot more I haven't thought of yet.
  60.  
  61. -- 
  62. Robert Stewart        | My opinions are usually my own.
  63. Datalytics, Inc.    | stew@datalytics.com
  64.  
  65.  
  66. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  67. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  68. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  69. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  70. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  71.